/*


 */

package jas.http.server;

import jas.http.logging.DateRequestLineResponseCodeIPHttpLogger;
import jas.http.logging.HttpLogger;
import jas.http.response.HttpResponseFactory;
import jas.http.response.HttpResponseFactoryImpl;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * The standard configuration for an HttpServer reading from the <code>web</code> folder,
 * and listening on port 8080 if it is available.
 * The <code>ThreadedConnectionHandler</code> is used to make the server multi-threaded.
 */
public class StdHttpServerFactory implements HttpServerFactory {
    private HttpLogger logger;
    private HttpResponseFactory factory;
    
    public StdHttpServerFactory() {
        logger = null;
        factory = new HttpResponseFactoryImpl("webhome/web", "DOOM WebServer Alpha");
    }
    public StdHttpServerFactory(HttpResponseFactory factory) {
        logger = null;
        this.factory = factory;
    }
    public StdHttpServerFactory(HttpLogger logger, HttpResponseFactory factory) {
        this.logger = logger;
        this.factory = factory;
    }
    
    public int getListenPort() {
        return 8080;
    }

    public HttpLogger createLogger() {
        if (logger == null)
            logger = new DateRequestLineResponseCodeIPHttpLogger(System.out, System.err);
        return logger;
    }

    public ConnectionHandler createConnectionHandler() {
        return new ThreadedConnectionHandler(factory, createLogger(), new ThreadPoolExecutor(2, 10, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()));
    }
}
